/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.fsiebert.polytech.db.mediatheque.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Florent
 */
@Entity
@Table(name = "Emprunt")
@NamedQueries({
    @NamedQuery(name = "Emprunt.findAll", query = "SELECT e FROM Emprunt e"),
    @NamedQuery(name = "Emprunt.findByDateFinPrevue", query = "SELECT e FROM Emprunt e WHERE e.dateFinPrevue = :dateFinPrevue"),
    @NamedQuery(name = "Emprunt.findByNumRenouvellement", query = "SELECT e FROM Emprunt e WHERE e.numRenouvellement = :numRenouvellement"),
    @NamedQuery(name = "Emprunt.findByDateRendu", query = "SELECT e FROM Emprunt e WHERE e.dateRendu = :dateRendu"),
    @NamedQuery(name = "Emprunt.findByIdEmprunt", query = "SELECT e FROM Emprunt e WHERE e.idEmprunt = :idEmprunt")})
public class Emprunt implements Serializable {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @NotNull
    @Column(name = "DateFinPrevue", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateFinPrevue;
    @Basic(optional = false)
    @NotNull
    @Column(name = "NumRenouvellement", nullable = false)
    private int numRenouvellement;
    @Column(name = "DateRendu")
    @Temporal(TemporalType.DATE)
    private Date dateRendu;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idEmprunt", nullable = false)
    private Integer idEmprunt;
    @JoinTable(name = "Emprunt_Exemplaire", joinColumns = {
        @JoinColumn(name = "NumeroEmprunt", referencedColumnName = "idEmprunt", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "NumeroArticle", referencedColumnName = "NumeroArticle", nullable = false)})
    @ManyToMany
    private List<Exemplaire> exemplaireList;
    @JoinColumn(name = "NoCarte", referencedColumnName = "NoCarte", nullable = false)
    @ManyToOne(optional = false)
    private Adherent noCarte;

    public Emprunt() {
    }

    public Emprunt(Integer idEmprunt) {
        this.idEmprunt = idEmprunt;
    }

    public Emprunt(Integer idEmprunt, Date dateFinPrevue, int numRenouvellement) {
        this.idEmprunt = idEmprunt;
        this.dateFinPrevue = dateFinPrevue;
        this.numRenouvellement = numRenouvellement;
    }

    public Date getDateFinPrevue() {
        return dateFinPrevue;
    }

    public void setDateFinPrevue(Date dateFinPrevue) {
        this.dateFinPrevue = dateFinPrevue;
    }

    public int getNumRenouvellement() {
        return numRenouvellement;
    }

    public void setNumRenouvellement(int numRenouvellement) {
        this.numRenouvellement = numRenouvellement;
    }

    public Date getDateRendu() {
        return dateRendu;
    }

    public void setDateRendu(Date dateRendu) {
        this.dateRendu = dateRendu;
    }

    public Integer getIdEmprunt() {
        return idEmprunt;
    }

    public void setIdEmprunt(Integer idEmprunt) {
        this.idEmprunt = idEmprunt;
    }

    public List<Exemplaire> getExemplaireList() {
        return exemplaireList;
    }

    public void setExemplaireList(List<Exemplaire> exemplaireList) {
        this.exemplaireList = exemplaireList;
    }

    public Adherent getNoCarte() {
        return noCarte;
    }

    public void setNoCarte(Adherent noCarte) {
        this.noCarte = noCarte;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idEmprunt != null ? idEmprunt.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Emprunt)) {
            return false;
        }
        Emprunt other = (Emprunt) object;
        if ((this.idEmprunt == null && other.idEmprunt != null) || (this.idEmprunt != null && !this.idEmprunt.equals(other.idEmprunt))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "eu.fsiebert.polytech.db.mediatheque.entity.Emprunt[ idEmprunt=" + idEmprunt + " ]";
    }
    
}
